home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / PROBLEMS / BENCHMARK / BOGO / c / bogomips
Text File  |  1995-04-23  |  1KB  |  70 lines

  1. /*
  2.  *                Standalone BogoMips program
  3.  *
  4.  * Based on code Linux kernel code in init/main.c and
  5.  * include/linux/delay.h
  6.  *
  7.  * For more information on interpreting the results, see the BogoMIPS
  8.  * Mini-HOWTO document.
  9.  *
  10.  * version: 1.3 
  11.  *  author: Jeff Tranter (Jeff_Tranter@Mitel.COM)
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <time.h>
  16.  
  17. #ifdef CLASSIC_BOGOMIPS
  18. /* the original code from the Linux kernel */
  19. static __inline__ void delay(int loops)
  20. {
  21.   __asm__(".align 2,0x90\n1:\tdecl %0\n\tjns 1b": :"a" (loops):"ax");
  22. }
  23. #endif
  24.  
  25. #ifdef QNX_BOGOMIPS
  26. /* version for QNX C compiler */
  27. void delay(int loops);
  28. #pragma aux delay = \
  29.      "l1:"       \
  30.      "dec eax"   \
  31.      "jns l1"    \
  32.      parm nomemory [eax] modify exact nomemory [eax];
  33. #endif
  34.  
  35. #ifdef PORTABLE_BOGOMIPS
  36. /* portable version */
  37. static void delay(int loops)
  38. {
  39.   long i;
  40.   for (i = loops; i >= 0 ; i--)
  41.     ;
  42. }
  43. #endif
  44.  
  45. int
  46. main(void)
  47. {
  48.   unsigned long loops_per_sec = 1;
  49.   unsigned long ticks;
  50.   
  51.   printf("Calibrating delay loop.. ");
  52.   fflush(stdout);
  53.   
  54.   while ((loops_per_sec <<= 1)) {
  55.     ticks = clock();
  56.     delay(loops_per_sec);
  57.     ticks = clock() - ticks;
  58.     if (ticks >= CLOCKS_PER_SEC) {
  59.       loops_per_sec = (loops_per_sec / ticks) * CLOCKS_PER_SEC;
  60.       printf("ok - %lu.%02lu BogoMips\n",
  61.           loops_per_sec/500000,
  62.          (loops_per_sec/5000) % 100
  63.          );
  64.       return 0;
  65.     }
  66.   }
  67.   printf("failed\n");
  68.   return -1;
  69. }
  70.